using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _controls_ListWorkItems : System.Web.UI.UserControl
{
    private string _userID;

    public string UserID
    {
        set
        {
            this._userID = value;
            RepeaterDataBind();
        }
    }

    public string EmptyText
    {
        set
        {
            this.lblNothing.Text = value;
        }
    }

    public int ItemsCount
    {
        get
        {
            return this.rptWorkItems.Items.Count;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RepeaterDataBind();
        }
    }

    private void RepeaterDataBind()
    {
        if (_userID == string.Empty)
        {
            this.rptWorkItems.DataSource = IMadeThisService.Current.GetFriendsWorkItems();
        }
        else
        {
            this.rptWorkItems.DataSource = IMadeThisService.Current.GetUserWorkItems(_userID);
        }

        this.rptWorkItems.DataBind();

        this.lblNothing.Visible = this.rptWorkItems.Items.Count == 0;
        this.rptWorkItems.Visible = !(this.lblNothing.Visible);
    }

    public void Clear()
    {
        this.rptWorkItems.DataSource = null;
        this.rptWorkItems.DataBind();
    }

    protected string LoadImageIfExists(int ID, bool HasImage)
    {
        if (HasImage)
            return string.Format("_media/small/{0}.jpg", ID);

        return string.Empty;
    }
}
